<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<link rel="stylesheet" type="text/css" href="/skin/css/amazeui.min1.css" />
<link href="/user/css/style.css" rel="stylesheet" type="text/css" />
<script src="/user/js/jquery.js"></script>
<script src="/skin/js/toast.js"></script>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<title>个人中心-会员中心</title>
<script>
	// 设计稿 375px，1rem = 100px，换算方法：px值 ÷ 100 = rem值
	// 例如：设计稿标注12px → 12 ÷ 100 = 0.12rem
	(function(){
		var docEl = document.documentElement;
		var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
		function recalc() {
			var clientWidth = docEl.clientWidth;
			if (!clientWidth) return;
			docEl.style.fontSize = (clientWidth / 375 * 100) + 'px';
		}
		if (!document.addEventListener) return;
		window.addEventListener(resizeEvt, recalc, false);
		document.addEventListener('DOMContentLoaded', recalc, false);
		recalc();
	})();
</script>
<style>
	:root{ --card:#fff; --line:#eef2f7; --text:#0f172a; --muted:#9aa3b2; --primary:#253043; }
	body{ background:#f3f5f8; }
	/* 顶部标题 */
	/* 表单卡片 */
	.form-card{ background:var(--card); margin:0.2rem 0; overflow:hidden; }
	.form-item{ display:flex; align-items:center; padding:0.14rem 0.16rem; border-bottom:0.01rem solid var(--line); position:relative; }
	.form-item:last-child{ border-bottom:0; }
	/* 省市区选择框的form-item需要更高的z-index */
	.form-item.region-item{ z-index:100; }
	.form-label{ width:0.88rem; flex:0 0 0.88rem; color:#1f2937; font-weight:700; font-size:0.14rem; }
	.form-control{ flex:1; display:flex; align-items:center; gap:0.08rem; min-width:0; }
	.form-control input[type=text]{ width:100%; border:0; background:transparent; outline:none; font-size:0.14rem; color:#111827; padding:0; margin:0; }
	.form-control input::placeholder{ color:#c0c7d2; }
	/* 所在地区的3个下拉横向排布 */
	.region-group{ display:flex; flex:1; position:relative; z-index:100; margin:0; padding:0; min-width:0; align-items:center; }
	.region-group select{ flex:1; border:0; background:transparent; font-size:0.15rem; color:#111827; padding:0; margin:0; margin-right:0.08rem; outline:none; position:relative; z-index:100; min-width:0; -webkit-appearance:none; appearance:none; text-indent:0; }
	.region-group select:first-child{ margin-left:0; }
	.region-group select:last-child{ margin-right:0; }
	.region-arrow{ margin-left:0.08rem; color:#c0c7d2; flex-shrink:0; }
	/* 开关区域 */
	.switch-row{ background:var(--card); margin:0.12rem 0; padding:0.16rem; display:flex; align-items:center; justify-content:space-between; }
	/* iOS 风格开关 */
	.switch{ position:relative; width:0.56rem; height:0.32rem; background:#d1d5db; border-radius:999px; transition:.2s; }
	.switch input{ display:none; }
	.switch .knob{ position:absolute; top:0.03rem; left:0.03rem; width:0.26rem; height:0.26rem; background:#fff; border-radius:50%; transition:.2s; }
	.switch input:checked + .knob{ left:0.27rem; }
	.switch.active{ background:#253043; }
	/* 提交按钮 */
	.page-actions{ padding:0.16rem 0.12rem 0.24rem; }
	.primary-btn{ width:100%; height:0.48rem; border:0; border-radius:0.02rem; background:#253043; color:#fff; font-size:0.16rem; font-weight:700; }
</style>
</head>
<body class="body">
<div class="editzl">
	<header id="header">
		<section class="head-b head-b1">
			<span class="u-left"><a href="javascript:history.go(-1);" class="back"><img src="/skin/img/back.png"/></a></span>
			<h1 id="t0">新建收货地址</h1>
			<div class="u-right" href="#">
				<a href="/" class="hSearch right"><img src="/skin/img/i_home.png"/></a>
			</div>
		</section>
	</header>
	<form class="xx">
		<div class="form-card">
			<div class="form-item">
				<div class="form-label">姓名</div>
				<div class="form-control">
					<input type="text" name="t11" placeholder="填写收货人姓名" value="" />
				</div>
			</div>
			<div class="form-item">
				<div class="form-label">电话</div>
				<div class="form-control">
					<input type="text" name="t12" placeholder="填写联系电话" value="" />
				</div>
			</div>
			<div class="form-item region-item">
				<div class="form-label">省</div>
				<div class="form-control">
					<div class="region-group">
						<select name="province" id="province">{$pro}</select>
					</div>
					<span class="region-arrow"></span>
				</div>
			</div>
			<div class="form-item region-item">
				<div class="form-label">市</div>
				<div class="form-control">
					<div class="region-group">
						<select name="city" id="city"></select>
					</div>
					<span class="region-arrow"></span>
				</div>
			</div>
			<div class="form-item region-item">
				<div class="form-label">区/县</div>
				<div class="form-control">
					<div class="region-group">
						<select name="county" id="county"></select>
					</div>
					<span class="region-arrow"></span>
				</div>
			</div>
			<div class="form-item">
				<div class="form-label">详细地址</div>
				<div class="form-control">
					<input type="text" name="t10" placeholder="小区、楼层、门牌号等" value="" />
				</div>
			</div>
		</div>
	
		<div class="switch-row">
			<div class="form-label" style="margin:0;flex: 0 0 1.5rem;">设置为默认地址</div>
			<label class="switch">
				<input type="checkbox" id="is_default_chk">
				<span class="knob"></span>
			</label>
			<input type="hidden" name="is_default" id="is_default_val" value="0" />
		</div>
	
		<div class="page-actions">
			<button class="primary-btn" type="button" onclick="edit();">保存地址</button>
		</div>
	</form>

	

</div>
</div>
<script>
$("#province").change(function (){
	index = $("#province option:selected").val();
	if(index>0){
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/Moudelu.php?m=m&a=province",
		data:"id="+index,
		success:function(d){
			if(d[0]==1){
				$("#city").html(d[1]);
			}
		}
	});
	}
});
$("#city").change(function (){
	index = $("#city option:selected").val();
	if(index>0){
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/Moudelu.php?m=m&a=city",
		data:"id="+index,
		success:function(d){
			if(d[0]==1){
				$("#county").html(d[1]);
			}
		}
	});
	}
});
document.addEventListener('DOMContentLoaded', function(){
	var chk = document.getElementById('is_default_chk');
	var val = document.getElementById('is_default_val');
	var switchEl = chk ? chk.closest('.switch') : null;
	
	function updateSwitchStyle() {
		if (switchEl && chk) {
			if (chk.checked) {
				switchEl.classList.add('active');
			} else {
				switchEl.classList.remove('active');
			}
		}
	}
	
	if(chk && val){
		// 初始化值和样式
		val.value = chk.checked ? '1' : '0';
		updateSwitchStyle();
		
		chk.addEventListener('change', function(){ 
			val.value = this.checked ? '1' : '0';
			updateSwitchStyle();
			console.log('默认地址状态:', val.value);
		});
	}
});
function edit(){
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/Moudelu.php?m=m&a=address_add",
		data:$(".xx").serialize(),
		success:function(d){
			if(d[0]==2){
				window.location.href='login.php';return false;
			}
			if(d[0]==0){
				showToast(d[1], 'error');
			}
			else{
				showToast(d[1], 'success');
				setTimeout(function(){
					{if($t==1)}
					window.location.href='/cart.php';
					{else}
					window.location.href='/user/address.php';
					{/if}
				}, 1500);
			}
		}
	});
}
</script>
{include(foot)}
</body>
</html>